package com.zhw.controller;

import com.zhw.pojo.Result;
import com.zhw.pojo.entry.CustomerContact;
import com.zhw.pojo.vo.ContactVO;
import com.zhw.service.ContactService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("contact")
@Slf4j
public class ContactController {

    @Autowired
    ContactService contactService;


    @GetMapping("list")
    public Result getContact(Integer cusId) {
        log.info("查询当前交互信息：{}", cusId);
        List<ContactVO> list = contactService.list(cusId);
        return Result.success(list);
    }


    @PostMapping("add")
    public Result addContact(@RequestBody CustomerContact customerContact) {
        log.info("添加一个客户的交互信息：{}", customerContact);
        contactService.add(customerContact);
        return Result.success();
    }

    @GetMapping("{id}")
    public Result getContactByID(@PathVariable Integer id) {
        log.info("获取一个客户的交互信息：{}", id);
        CustomerContact customerContact = contactService.getContactByID(id);
        return Result.success(customerContact);
    }

    @DeleteMapping("{id}")
    public Result deleteContactByID(@PathVariable Integer id) {
        log.info("删除一个客户的交互信息：{}", id);
        contactService.deleteContactById(id);
        return Result.success();
    }


    @PutMapping
    public Result update(@RequestBody CustomerContact customerContact) {
        log.info("修改交互信息：{}", customerContact);
        contactService.update(customerContact);
        return Result.success();
    }
}
